package tech.aistar.day09;

import java.util.Date;

/**
 * 本类用来演示:+和append效率
 *
 * @author: success
 * @date: 2021/3/18 9:41 上午
 */
public class PlusAndAppendDemo {
    public static void main(String[] args) {
        append();
    }

    public static void plus(){
        String str = "";
        long before = new Date().getTime();
        for (int i = 0; i < 100000; i++) {
            str+=i;
        }
        long after = new Date().getTime();
        System.out.println(after - before);
    }

    //效率高
    public static void append(){
        StringBuilder builder = new StringBuilder();
        long before = new Date().getTime();
        for (int i = 0; i < 100000; i++) {
            builder.append(i);//+=
        }
        long after = new Date().getTime();
        System.out.println(after - before);
    }

}
